package com.marion.study.service;

import com.marion.study.entity.UserEntity;
import com.marion.study.model.User;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Service
public class AuthService {

    /**
     * 定义权限内存
     */
    public static Map<Integer, UserEntity> auth = new HashMap<>();

    /**
     * 通过ID获取
     */
    public boolean isLogin(int id) {
        return Optional.ofNullable(auth.get(id)).isPresent();
    }

    /**
     * 登陆
     */
    public boolean login(UserEntity user) {
        auth.put(user.getId(), user);
        return true;
    }

    /**
     * 退出
     */
    public boolean userExit() {
        auth.clear();
        return true;
    }
}
